#include <stdio.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <stdlib.h>
#include <linux/input.h>

#define path  "/dev/input/event3"

struct input_event key_input_event;

int main(int argc, char** argv)
{
    int error = -20;
    int fd = open(path,O_RDONLY);
    if (fd < 0){
        printf("open file %s failed!\r\n",path);
        return -1;
    }
    do {
        error = read(fd, &key_input_event, sizeof(key_input_event));
        printf("the error value is %d\n",error);
        if (error < 0){
            printf("read file failed !\n");
        }
        if (1){
            //if ((key_input_event.type == 1) && (key_input_event.code == 2)){
            if (key_input_event.value == 0){
                printf("the value is 0\n");
            }else{
                printf("the value is 1\n");
            }
            usleep(5000000);
        }
    } while(1);
    error = close(fd);
    if (error < 0){
        printf("close the file failed\n");
    }
    return 0;
}